package com.redpacketcover.rc.user;

import android.widget.Toast;

import androidx.lifecycle.MutableLiveData;

import com.redpacketcover.rc.base.BaseApplication;
import com.redpacketcover.rc.base.BaseResponseBean;
import com.redpacketcover.rc.base.BasicPresenter;
import com.redpacketcover.rc.base.ModelObserver;
import com.redpacketcover.rc.base.ViewModelFactory;
import com.redpacketcover.rc.bean.GoodsRecord;
import com.redpacketcover.rc.bean.UserBean;
import com.redpacketcover.rc.goods.MatchMode;
import com.redpacketcover.rc.util.UserInfo;

import java.util.HashMap;
import java.util.List;

public class UserPresenter extends BasicPresenter<IUserView, UserMode> {
    @Override
    public UserMode getModeInstance() {
        return ViewModelFactory.getInstance(UserMode.class, mView);
    }

    /*TODO接口api管理*/
    /**
     * 获取用户信息
     */
    public void getUserInfo() {
        HashMap<String, Object> params = new HashMap<>();
        MutableLiveData<BaseResponseBean<String>> liveData = mMode.getUserInfo(params);
        if (!liveData.hasObservers()) {
            liveData.observe(mView, new ModelObserver<String>() {
                @Override
                public void onSuccess(String data) {

                    UserInfo.Companion.getInstance().setLoginToken(data);

                }

                @Override
                public void onFailed(int code, String errMsg) {
                    Toast.makeText(BaseApplication.getInstance(), errMsg, Toast.LENGTH_LONG).show();
                }

            });
        }
    }
}
